package com.ruoyi.kafka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: kafka 消息生产者 
 * @ClassName: SendController
 * @author syc
 * @date: 2022年6月1日 下午4:54:53
 */
@RestController
@RequestMapping(value = "/producer")
public class SendController {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    /***
     *	发送消息
     * topic:要发送的队列
     * msg:发送的消息
     */
    @GetMapping(value = "/send/{topic}/{msg}")
    public String send(@PathVariable(value = "topic")String topic,@PathVariable(value = "msg")String msg){
        //消息发送
       
    	System.out.println(topic+"............" +msg );
    	kafkaTemplate.send(topic,msg);
        return "SUCCESS";
    }
}

